package com.coder520.user.service;

import com.coder520.common.utils.MD5Utils;
import com.coder520.user.dao.UserMapper;
import com.coder520.user.entity.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.io.UnsupportedEncodingException;
import java.security.NoSuchAlgorithmException;

@Service("userServiceImpl")
public class UserServiceImpl implements UserService {

    @Autowired
    private UserMapper userMapper;


    /**
     * @Author: Lin
     * @Param:  * @param username
     * @Description: 根据用户名查找用户
     * @Date: 18:04 2017/9/12
     */
    @Override
    public User findUserByUsername(String username) {
        User user = null;
        try {
            user = userMapper.selectByUsername(username);
        }catch (Exception e){
            e.printStackTrace();
            throw e;
        }
        return user;
    }


    @Override
    public void createUser(User user) throws UnsupportedEncodingException, NoSuchAlgorithmException {
        user.setPassword(MD5Utils.encryptPassword(user.getPassword()));
        userMapper.insertSelective(user);
    }

}
